Code: Select all
((val)=((val)&15) + ((val)>>4)*10)
Seb
Code: Select all
((val)=((val)&15) + ((val)>>4)*10)
Code: Select all
#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
Code: Select all
DECLARE FUNCTION BitRight! (value!, tm)
DECLARE FUNCTION BitLeft! (value!, tm)
CLS
x! = BitLeft(1234567, 2)
PRINT x!
y! = BitRight(x!, 2)
PRINT y!
FUNCTION BitLeft (value!, tm)
DIM Newval!, TempVal!, x, y, z
TempVal! = value!
FOR y = 1 TO tm
Newval! = 0: z = 1
FOR x = 1 TO 31 'Leftmost bit #32 lost.
IF (TempVal! AND z) THEN
Newval! = Newval! + (z * 2)
END IF
z = z * 2 'Next bit over.
NEXT x
TempVal! = Newval!
NEXT y
BitLeft = TempVal!
END FUNCTION
FUNCTION BitRight (value!, tm)
DIM Newval!, TempVal!, x, y, z
TempVal! = value!
FOR y = 1 TO tm
Newval! = 0: z = 1073741824
'My method won't work if number is full 32-bit...
'because QB will overflow on the starting number.
FOR x = 1 TO 30 'Rightmost bit #1 lost.
IF (TempVal! AND z) THEN
Newval! = Newval! + (z / 2)
END IF
z = z / 2 'Next bit over.
NEXT x
TempVal! = Newval!
NEXT y
BitRight = TempVal!
END FUNCTION
YesSebMcClouth wrote:You have to bring e.g 8 back to
1000 and then according to val>>4 it would 0001 or 1?
correct?
grtz
Seb
Code: Select all
'Based on:
'#define BCD_TO_BIN(val) ((val)=((val)&15) + ((val)>>4)*10)
FUNCTION BCD_TO_BIN(value!)
BCD_TO_BIN = (value! AND 15) + (BitRight(value!,4)*10)
END FUNCTION
Code: Select all
long x=1234;
BCD_TO_BIN(x);
Code: Select all
DIM x as LONG: x=1234
x=BCD_TO_BIN(x)
'or just x=BCD_TO_BIN(1234)
Code: Select all
DECLARE FUNCTION BitRight! (value!, tm)
DECLARE FUNCTION BitLeft! (value!, tm)
DECLARE FUNCTION BCD2BIN (val)
FUNCTION BCD2BIN (VAL)
'((val)=((val)&15) + ((val)>>4)*10)
BCD2BIN=(val...
END Function
FUNCTION BitLeft (value!, tm)
DIM Newval!, TempVal!, x, y, z
TempVal! = value!
FOR y = 1 TO tm
Newval! = 0: z = 1
FOR x = 1 TO 31 'Leftmost bit #32 lost.
IF (TempVal! AND z) THEN
Newval! = Newval! + (z * 2)
END IF
z = z * 2 'Next bit over.
NEXT x
TempVal! = Newval!
NEXT y
BitLeft = TempVal!
END FUNCTION
FUNCTION BitRight (value!, tm)
DIM Newval!, TempVal!, x, y, z
TempVal! = value!
FOR y = 1 TO tm
Newval! = 0: z = 1073741824
'My method won't work if number is full 32-bit...
'because QB will overflow on the starting number.
FOR x = 1 TO 30 'Rightmost bit #1 lost.
IF (TempVal! AND z) THEN
Newval! = Newval! + (z / 2)
END IF
z = z / 2 'Next bit over.
NEXT x
TempVal! = Newval!
NEXT y
BitRight = TempVal!
END FUNCTION
Code: Select all
((val)=((val)&15) + ((val)>>4)*10)
Code: Select all
((val)=((val)&15)+(BitRight(val),4)*10)
Code: Select all
TYPE tm
Sec as integer
Min as integer
Hour as integer
mDay as integer
Mon as integer
Year as integer
wDay as integer
yDay as integer
Isdst as integer
end type
DIM SHARED tmtime as tm
CLS
TimeInit
PRINT tmtime.Hour; tmtime.Min; tmtime.Sec
PRINT tmtime.Mday; tmtimeMon; tmtime.Year
FUNCTION BCD2BIN (Value!)
BCD2BIN=(Value! and 15)+(BitRight(Value!,4)*10)
END Function
FUNCTION BitLeft (value!, tm)
DIM Newval!, TempVal!, x, y, z
TempVal! = value!
FOR y = 1 TO tm
Newval! = 0: z = 1
FOR x = 1 TO 31 'Leftmost bit #32 lost.
IF (TempVal! AND z) THEN
Newval! = Newval! + (z * 2)
END IF
z = z * 2 'Next bit over.
NEXT x
TempVal! = Newval!
NEXT y
BitLeft = TempVal!
END FUNCTION
FUNCTION BitRight (value!, tm)
DIM Newval!, TempVal!, x, y, z
TempVal! = value!
FOR y = 1 TO tm
Newval! = 0: z = 1073741824
'My method won't work if number is full 32-bit...
'because QB will overflow on the starting number.
FOR x = 1 TO 30 'Rightmost bit #1 lost.
IF (TempVal! AND z) THEN
Newval! = Newval! + (z / 2)
END IF
z = z / 2 'Next bit over.
NEXT x
TempVal! = Newval!
NEXT y
BitRight = TempVal!
END FUNCTION
FUNCTION CMOSRead (addr)
out &h70, addr
CMOSRead=inp(&h71)
END FUNCTION
SUB TimeInit
do
tmtime.sec = CMOSREAD(0)
tmtime.min = CMOSREAD(2)
tmtime.hour = CMOSREAD(4)
tmtime.mday = CMOSREAD(7)
tmtime.mon = CMOSREAD(8)-1
tmtime.year = CMOSREAD(9)
loop while (tmtime.sec = CMOSREAD(0))
BCD2BIN(tmtime.sec)
BCD2BIN(tmtime.min)
BCD2BIN(tmtime.hour)
BCD2BIN(tmtime.mday)
BCD2BIN(tmtime.mon)
BCD2BIN(tmtime.year)
startuptime = mktime(&time)
END SUB