? 8-bit signed? (Page 1) ● SmileBASIC Source Forums

Sign In

*Usernames are case-sensitive
Forgot my password

8-bit signed?

  • #1 ✎ 28 SaladFingers Is it possible to convert an integer to an 8bit signed integer? Edit: I guess I wasn’t trying hard enough, my integer was already 1 byte long, just needed to get rid of the most significant bit. Edit 2: I was wrong, I still need some help. I have a number, for example &B11111011 (251) and I need it to be represented as a negative, signed number. Posted Edited by SaladFingers
  • #2 ✎ 1464 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself Second Year My account is over 2 years old Website For converting a signed number to a larger integer type (8 bit -> 32 bit) you can use the fact that >> preserves the highest bit: X<<(32-8)>>(32-8)for example, &B11111011 <<24 &B11111011000000000000000000000000 >>24 &B11111111111111111111111111111011 (-5) Posted Edited by 12Me21
  • #3 ✎ 9 hanzo It is possible if the integer is in the range of -128 to 127. Could you refer to the following program? ACLS A%=256 WHILE A%<-128 || A%>127 INPUT"AN INTEGER (-128 TO 127)";A% WEND B%=A%+256*(A%<0) ?"8BIT SIGNED INT OF ";:?A% ?" = ";:?"&B";:?BIN$(B%,8); ?"(&H";:?HEX$(B%,2);:?")" Posted
  • #4 ✎ 9 hanzo I'm sorry I've lost your EDIT2 but it is very simple as follows. A%=&B11111011 ?A%-256*(A%>=128) Posted